﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using BA2009.Services;
using BA2009.Tests.Fakes;
using BA2009.Entities;

namespace BA2009.Tests.Services
{
    [TestClass]
    public class PageServiceTest
    {
        [TestMethod]
        public void find_all_should_return_10_item()
        { 
            PageService service=new PageService(new FakePageRepository(FakeBA2009Data.CreateTestPages()));

            IList<Page> pages=service.FindAll();

            Assert.IsNotNull(pages);
            Assert.AreEqual(10,pages.Count);
        }

        [TestMethod]
        public void get_by_id_should_not_null_and_have_value()
        { 
            PageService service=new PageService(new FakePageRepository(FakeBA2009Data.CreateTestPages()));

            Page page=service.GetById(1);

            Assert.IsNotNull(page);
            Assert.AreEqual(1,page.PageID);
            Assert.AreEqual("Code1",page.Code);
            Assert.AreEqual("Desc1",page.Description);
        }

    

        //[TestMethod]
        //public void insert_deleted_get_by_id_integration_test()
        //{
        //    var service = new PageService();

        //    Page page = FakeBA2009Data.CreatePage();


        //    int id = service.Add(page);

        //    Assert.IsTrue(id > 0);

        //    //int id = 7;
        //    Page inserted = service.GetById(id);

        //    Assert.IsNotNull(inserted);

        //    Assert.AreEqual(id, inserted.PageID);

        //    Assert.AreEqual("PAGECODE", inserted.Code);

        //    bool isDeleted = service.Delete(inserted);
        //    Assert.AreEqual(true, isDeleted);

        //    Page deleted = service.GetById(id);

        //    Assert.IsNull(deleted);
        //}

        //[TestMethod]
        //public void update_test()
        //{
        //    var service = new PageService();

        //    Page page = FakeBA2009Data.CreatePage();


        //    int id = service.Add(page);

        //    Assert.IsTrue(id > 0);

        //    //int id = 7;
        //    Page inserted = service.GetById(id);

        //    Assert.IsNotNull(inserted);

        //    Assert.AreEqual(id, inserted.PageID);

        //    Assert.AreEqual("PAGECODE", inserted.Code);

        //    inserted.Code = "CODE_MODIFIED";
        //    inserted.PageName = "Name modified";

        //    service.Update(inserted);

        //    Page updated = service.GetById(inserted.GetPKValue());

        //    Assert.IsNotNull(updated);
        //    Assert.AreEqual("CODE_MODIFIED", updated.Code);
        //    Assert.AreEqual("Name modified", updated.PageName);

        //    bool isDeleted1 = service.Delete(updated);
        //    Assert.AreEqual(true, isDeleted1);
        //}

    }
}
